use sea_orm::ActiveValue::Set;
use sea_orm::{ActiveModelTrait, EntityTrait};
use common::ctx::get_db_by_key;
use common::error::MyError;
use entity::member_dungeon;
use entity::prelude::MemberDungeon;

pub struct MemberDungeonManager {}

const OPEN_MEMBER_DUNGEON_LEVEL: &str = "1|3,2|3,3|3,4|3,5|3,6|3,7|3,8|3,9|3,11|3,12|3,13|3,14|3,15|3,16|1,17|3,21|3,22|3,23|3,24|3,25|3,26|3,27|3,31|3,32|3,33|3,34|3,35|3,36|3,37|3,40|3,41|2,42|3,43|3,44|3,45|3,50|3,51|3,52|3,53|3,60|3,61|3,62|2,63|3,64|3,65|3,67|3,70|3,71|3,72|3,73|3,74|3,75|3,76|3,77|3,80|3,81|3,82|3,83|3,84|3,85|3,86|3,87|3,88|3,89|3,90|3,91|2,92|3,93|3,100|3,101|3,102|3,103|3,104|3,110|3,111|3,112|3,140|3,141|3,502|3,511|3,515|1,518|1,521|3,1000|3,1500|3,1501|3,1502|3,1507|1,3506|3,10000|3";

impl MemberDungeonManager {
    pub async fn open_dungeon(uid: u32) -> Result<bool, MyError> {
        let entity = MemberDungeon::find_by_id(uid)
            .one(&*get_db_by_key("taiwan_cain")?)
            .await?
            .ok_or(MyError::ServerError(format!(
                "member_dungeon [{:?}] does not exist",
                uid
            )))?;
        let mut entity: member_dungeon::ActiveModel = entity.into();
        entity.dungeon = Set(OPEN_MEMBER_DUNGEON_LEVEL.to_string());
        let _result = entity.update(&*get_db_by_key("taiwan_cain")?).await?;
        Ok(true)
    }
}